

module.exports = class poster_dao extends require('../sql/poster_sql'){


    /**
     * 获取公告列表
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getPosterData(req,resp){
        let query = req.query;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getPosterDataSql(currPage,pageNum)
        let total = await this.getPosterDataTotal()
        resp.send({data,total:total[0].count})
    }


    /**
     * 发布公告
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async addPoster(req,resp){
        let body = req.body;
        let communityname = body.communityname;
        let title = body.title;
        let content = body.content;
        let results = await this.addPosterSql(communityname,title,content)
        resp.send(results)
    }


    /**
     * 删除公告
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delPoster(req,resp){
        let p_id = req.query.p_id
        let results = await this.delPosterSql(p_id)
        resp.send(results)
    }

    /**
     * 获取智能维修列表
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getRepairData(req,resp){
        let query = req.query;
        let repairtype = query.repairtype;
        let homename = query.homename;
        let resultstatus = query.resultstatus;
        let startDate = query.startDate;
        let endDate = query.endDate;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getRepairDataSql(repairtype,homename,resultstatus,startDate,endDate,currPage,pageNum);
        let total = await this.getRepairDataTotal(repairtype,homename,resultstatus,startDate,endDate)
        resp.send({data,total:total[0].count})
    }

    // /**
    //  * 获取家居维修列表
    //  * @param req
    //  * @param resp
    //  * @returns {Promise<void>}
    //  */
    // static async getRepairHouse(req,resp){
    //     let query = req.query;
    //     let homename = query.homename;
    //     let repairstatus = query.repairstatus;
    //     let startDate = query.startDate;
    //     let endDate = query.endDate;
    //     let pageNum = query.pageNum;
    //     let currPage = query.currPage;
    //
    //     let data = await this.getRepairHouseSql(homename,repairstatus,startDate,endDate,currPage,pageNum);
    //     let total = await this.getRepairHouseTotal(homename,repairstatus,startDate,endDate)
    //     resp.send({data,total:total[0].count})
    // }

    /**
     * 删除维修内容
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delRepair(req,resp){
        let r_id = req.query.r_id
        let results = await this.delRepairSql(r_id)
        resp.send(results)
    }


    /**
     * 智能设备处理
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateSmartRepair(req,resp){
        let body = req.body;
        let r_id = body.r_id;
        let homename = body.homename;
        let housename = body.housename;
        let repaircontent = body.repaircontent;
        let resultcontent = body.resultcontent;
        let resultstatus = body.resultstatus;

        let results = await this.updateSmartRepairSql(r_id,homename,housename,repaircontent,resultcontent,resultstatus)
        resp.send(results)
    }


    // /**
    //  * 家具维修处理
    //  * @param req
    //  * @param resp
    //  * @returns {Promise<void>}
    //  */
    // static async updateHouseRepair(req,resp){
    //     let body = req.body;
    //     let r_id = body.r_id;
    //     let homename = body.homename;
    //     let housename = body.housename;
    //     let housetext = body.housetext;
    //     let houseresult = body.houseresult;
    //     let repairstatus = body.repairstatus;
    //
    //     let results = await this.updateHouseRepairSql(r_id,homename,housename,housetext,houseresult,repairstatus)
    //     resp.send(results)
    // }


    /**
     * 获取反馈列表
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async getFeedBack(req,resp){
        let query = req.query;
        let username = query.username;
        let feedtext = query.feedtext;
        let startDate = query.startDate;
        let endDate = query.endDate;
        let feedresult = query.feedresult;
        let feedstatus = query.feedstatus;
        let pageNum = query.pageNum;
        let currPage = query.currPage;

        let data = await this.getFeedBackSql(username,feedtext,startDate,endDate,feedresult,feedstatus,currPage,pageNum);
        let total = await this.getFeedBackTotal(username,feedtext,startDate,endDate,feedresult,feedstatus)
        resp.send({data,total:total[0].count})
    }

    /**
     * 用户提交维修
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async addRepair(req,resp){
        let body = req.body;
        let homename = body.homename;
        let housename = body.housename;
        let repairtype = body.repairtype;
        let repaircontent = body.repaircontent;
        let h_id = body.h_id;
        let results = await this.addRepairSql(homename,housename,repairtype,repaircontent,h_id);
        resp.send(results)
    }


    /**
     * 修改评分
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateScore(req,resp){
        let body = req.body;
        let f_id = body.f_id;
        let feedscore = body.feedscore;
        let results = await this.updateScoreSql(f_id,feedscore);
        resp.send(results)
    }

    /**
     * 根据f_id删除反馈
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delFeedback(req,resp){
        let f_id = req.query.f_id;
        let results = await this.delFeedbackSql(f_id)
        resp.send(results)
    }

    /**
     * 批量删除反馈内容
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async delFeedbackData(req,resp){
        let results = await this.delFeedbackDataSql(req.query.ids)
        resp.send(results)
    }


    /**
     * 处理反馈
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updateFeedback(req,resp){
        let body = req.body;
        let f_id = body.f_id;
        let feedresult = body.feedresult;
        let feedstatus = body.feedstatus;

        let results = await this.updateFeedbackSql(f_id,feedresult,feedstatus)
        resp.send(results)
    }

    /**
     * 用户提交反馈
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async addFeedBack(req,resp){
        let body = req.body;
        let username = body.username;
        let feedtext = body.feedtext;
        let results = await this.addFeedBackSql(username,feedtext);
        resp.send(results)
    }


    /**
     * 更新阅读量
     * @param req
     * @param resp
     * @returns {Promise<void>}
     */
    static async updatePostNum(req,resp){
        let body = req.body;
        let p_id = body.p_id;
        let postnum = body.postnum;
        let results = await this.updatePostNumSql(p_id,postnum);
        resp.send(results)
    }


}